<!--suppress ALL -->
<include file="./Template/header.html" />
<link rel="stylesheet" type="text/css" href="/Template/css/common.css">
<link rel="stylesheet" type="text/css" href="/Template/css/confirmOrderPrice.css">
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">

    $(function() {
        //初始化页面配置
        document.title = "确认订单";

        wx.config({
            debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
            appId: '{$webarr.appId}', // 必填，公众号的唯一标识
            timestamp: '{$config.timestamp}', // 必填，生成签名的时间戳
            nonceStr: '{$config.noncestr}', // 必填，生成签名的随机串
            signature: '{$config.signature}', // 必填，签名，见附录1
            jsApiList: ['chooseWXPay'] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
        });

        wx.ready(function(){});

        function callpay(){
            if (typeof WeixinJSBridge == "undefined"){
                if( document.addEventListener ){
                    alert("必须在微信中支付");
                    document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
                }else if (document.attachEvent){
                    alert("必须在微信中支付2");
                    document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
                    document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
                }
            }else{
                onBridgeReady();
            }

            onBridgeReady();
        }

        function onBridgeReady(){
            wx.chooseWXPay({
                timestamp: '{$webarr.timeStamp}', // 支付签名时间戳，注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
                nonceStr: '{$webarr.nonceStr}', // 支付签名随机串，不长于 32 位
                package: '{$webarr.package}', // 统一支付接口返回的prepay_id参数值，提交格式如：prepay_id=***）
                signType: '{$webarr.signType}', // 签名方式，默认为'SHA1'，使用新版支付需传入'MD5'
                paySign: '{$webarr.paySign}', // 支付签名
                success: function (res) {
                    // 支付成功后的回调函数
					alert('恭喜您兑换成功！请耐心等待我们工作人员与您联系。')
                    window.location.href = "{$successUrl}";
                }
            });
        }

        $(".bg-pay").on("click",function() {
            if(parseFloat('{$giftOrder.price}') > 0) {
                callpay();
			} else {
                $.ajax({
                    url:"/wechat/order/giftForFree",
                    type:"post",
                    data:{
                        orderId:'{$order.order_id}',
                    },
                    dataType:"JSON",
                    beforeSend:function(){
                        $("#loadingToast").show();
                    },
                    complete:function(){
                        $('#loadingToast').hide();
                    },
                    success:function(data){
                        if(data.code != 200) {
                            alert(data.msg);
                        } else {
                            alert('恭喜您兑换成功！请耐心等待快递上门哦，虚拟物品的领取请尽快点击公众号里的"平台服务"联系我们客服吧');
                            window.location.href = "{$successUrl}";
                        }
                    },
                })
			}

        })

    });

</script>
<div class="confirm-order">
	<div class="goods-info">
		<div class="goods-img" style="background: url('{$order.image}')no-repeat center;background-size: cover;"></div>
		<div class="goods">
			<p class="goods-title color-font">{$order.product_name}</p>
		</div>
		<div class="tag bg-yellow">
			<span>中奖产品</span>
		</div>
	</div>
	<div class="need-pay-price">
		<p class="color-font">需支付 {$giftOrder.price}</p>
	</div>
</div>
<div class="btn-weui bg-pay">
	<p>微信支付</p>
</div>

<!-- loading toast -->
<div id="loadingToast" class="weui_loading_toast" style="display: none;">
	<div class="weui_mask_transparent"></div>
	<div class="weui_toast small">
		<div class="weui_loading">
			<div class="weui_loading_leaf weui_loading_leaf_0"></div>
			<div class="weui_loading_leaf weui_loading_leaf_1"></div>
			<div class="weui_loading_leaf weui_loading_leaf_2"></div>
			<div class="weui_loading_leaf weui_loading_leaf_3"></div>
			<div class="weui_loading_leaf weui_loading_leaf_4"></div>
			<div class="weui_loading_leaf weui_loading_leaf_5"></div>
			<div class="weui_loading_leaf weui_loading_leaf_6"></div>
			<div class="weui_loading_leaf weui_loading_leaf_7"></div>
			<div class="weui_loading_leaf weui_loading_leaf_8"></div>
			<div class="weui_loading_leaf weui_loading_leaf_9"></div>
			<div class="weui_loading_leaf weui_loading_leaf_10"></div>
			<div class="weui_loading_leaf weui_loading_leaf_11"></div>
		</div>
		<p class="weui_toast_content">正在处理</p>
	</div>
</div>
<!--end loading toast-->